<template>
  <div>
    <Nav></Nav>
    <div v-if="status == 0">
      <div class="one">
        <div class="two">
          <div>
            <el-form ref="form" :model="search">
              <el-row>
                <el-col :span="12">
                  <el-form-item label="当前任务" label-width="80px" prop="currentNodeName">
                    <el-input v-model="search.currentNodeName" style="width: 200px" placeholder="请输入当前任务" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
          <div>
            <el-button type="primary" @click="cmdSearch">搜索</el-button>
            <el-button type="info" @click="cmdReset">重置</el-button>
          </div>
        </div>
      </div>
      <div>
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="currentNodeName" label="当前任务" align="center"></el-table-column>
          <el-table-column prop="flowName" label="流程名称" align="center"></el-table-column>
          <el-table-column prop="addName" label="申请人" align="center"></el-table-column>
          <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
          <!-- <el-table-column prop="address" label="状态"> </el-table-column> -->
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="addoption(scope.row.orunid, scope.row.currentNodeID, scope.row.preNodeID, scope.row.curAuthor)">处理</el-button>
              <el-button type="primary" size="small" @click="checkOption(scope.row.orunid,scope.row.currentNodeID)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="paginationStyle">
        <el-pagination v-if="total>0" background layout="total, prev, pager, next, jumper" :page-size="pageSize" @current-change="handleCurrentChange" :total="total"></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { getMyToDoList, sysModeAll, getAuditSearch } from '@/api/api'
import { getNode } from '@/unils/utils'
import { mapGetters } from 'vuex'
import swal from 'sweetalert'
import embodiment from '../process-management/processlist/embodiment'
import nav from '../../components/navigation'
import paging from '../../components/paging'
export default {
  components: {
    Embodiment: embodiment,
    Nav: nav,
    Paging: paging
  },
  data () {
    return {
      search: {
        currentNodeName: ''
      },
      status: 0,
      tableData: [],
      id: '',
      pageSize: 10,
      pageNum: 0,
      total: 0,
      //
      nodeIdId: 2,
      activeNames: ['2']
    }
  },
  mounted () {
    this.getDatas()
    // this.get_sysMode()
  },
  computed: {
    ...mapGetters(['jobAccount'])
  },
  methods: {
    getDatas () {
      let params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        jobAccount: this.jobAccount,
        modeID: '实施方案'
      }
      getMyToDoList(params)
        .then((res) => {
          // console.log(res)
          if (res.code == 200) {
            this.tableData = res.data.content
            this.total = res.data.totalElements
          } else {
            swal('错误', res.message || '网络连接错误', 'error')
          }
        })
        .catch((err) => {
          swal('错误', '网络连接错误', 'error')
        })
    },
    handleCurrentChange (val) {
      this.pageNum = val - 1
      this.getDatas()
    },
    cmdSearch () {
      let params = {
        currentNodeName: this.search.currentNodeName,
        pageNo: this.pageNum,
        pageSize: this.pageSize
      }
      getAuditSearch(params).then(res => {
        // console.log(res)
        if (res.code == 200) {
          this.tableData = res.data.content
          this.total = res.data.totalElements
        } else {
          swal('错误', res.message || '网络连接错误', 'warning')
        }
      }).catch((err) => {
        swal('错误', '网络连接错误', 'error')
      })
    },
    cmdReset () {
      this.$refs.form.resetFields()
      this.getDatas()
    },
    addoption (id, nodeId, preNodeId, curAuthor) {
      // console.log(getNode(nodeId))
      this.nodeIdId = getNode(nodeId)
      this.activeNames = [`${getNode(nodeId)}`]

      this.$router.push({ path: '/audit-process', query: { orunid: id, nodeIdId: this.nodeIdId, activeNames: this.activeNames, nodeId: nodeId, edit: true, preNodeId: preNodeId, curAuthor: curAuthor } })
    },
    checkOption (id, nodeId) {
      this.nodeIdId = getNode(nodeId)
      this.activeNames = [`${getNode(nodeId)}`]
      this.$router.push({ path: '/audit-process', query: { orunid: id, activeNames: this.activeNames, nodeId: nodeId } })
    },
    get_sysMode () {
      sysModeAll().then(res => {
        console.log(res)
      })
    }
  }
}
</script>
<style lang="less" scoped>
.one {
  line-height: 60px;
  .el-form {
    position: relative;
    top: 12px;
    margin-right: 10px;
  }
  .two {
    width: 80%;
    display: flex;
  }

  height: 60px;
  background-color: rgb(255, 255, 255);
  margin-bottom: 10px;
}
.cardBox {
  margin-bottom: 15px;
}
</style>